/* eslint-disable @typescript-eslint/ban-types */
import link from "@/api/link.js";
import apiUrl from "@/api/url.js";
const HomeModule: Object = {
  state: {
    // navBool: false,
    navBool: true,
    dialogFormVisible: false,
    uplistData: {},
    listdata: [],
  },
  mutations: {
    // 打开关闭侧边栏
    SET_NAV_BOOL(state: any) {
      state.navBool = !state.navBool;
    },
    // 打开弹窗
    SET_DIALOG(state: any, paylog: any) {
      state.dialogFormVisible = !state.dialogFormVisible;
      state.uplistData = paylog;
      // console.log("state.uplistData-", state.uplistData);
    },
    // 关闭弹窗
    DIALOG(state: any) {
      state.dialogFormVisible = !state.dialogFormVisible;
      window.location.reload();
    },
    // 获取列表数据
    LISTDATA(state: any, paylog: any) {
      state.listdata = paylog;
    },
  },
  getters: {},
  actions: {
    // 获取用户列表
    USERUPDATE_LIST(context: any) {
      link(apiUrl.userlist).then((resolve: any) => {
        context.commit("LISTDATA", resolve.data);
      });
    },
    // 删除用户
    DEL_DATA(context: any, paylog: any) {
      link(apiUrl.userlist + "/" + paylog.id, "DELETE").then((resolve: any) => {
        console.log(resolve);
        window.location.reload();
      });
    },
    // 获取公司列表
    COMPANYVEHICLES_LIST(context: any) {
      link(apiUrl.CompanyVehicles).then((resolve: any) => {
        context.commit("LISTDATA", resolve.data);
      });
    },
    // 删除公司
    DEL_VEHICLES(context: any, paylog: any) {
      link(apiUrl.CompanyVehicles + "/" + paylog.id, "DELETE").then(
        (resolve: any) => {
          window.location.reload();
        }
      );
    },
    // 获取外来车辆列表
    FOREIGNVEHICLES_LIST(context: any) {
      link(apiUrl.ForeignVehicles).then((resolve: any) => {
        context.commit("LISTDATA", resolve.data);
      });
    },
    // 添加外来车辆
    ADD_DRAWER(context: any, paylog: any) {
      link(apiUrl.ForeignVehicles, "POST", paylog).then((resolve: any) => {
        window.location.reload();
      });
    },
    // 删除已走外来车辆
    DEL_OUTSIDE(context: any, paylog: any) {
      link(apiUrl.ForeignVehicles + "/" + paylog.id, "DELETE").then(
        (resolve: any) => {
          window.location.reload();
        }
      );
    },
  },
};

export default HomeModule;
